<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <!-- <input type="text" id="username" />
        <input type="text" id="age" />
        <button id="btn">确定</button>
        <button id="del">删除肖自立</button>
        <button id="update">修改</button>
        <div id="box"></div> -->
        <h1>登录</h1>
        <input type="text" id="user" />
        <button>确定</button>
    </body>
    <script>
        window.onload = function () {
            let btn = document.querySelector('button')
            btn.onclick = function () {
                user = document.querySelector('#user').value
                localStorage.setItem('user', user)
                location.href = 'index2.html'
            }
            // sessionStorage.username = '张三'
            // console.log(localStorage.key(0))
            // localStorage.removeItem('username')
            // localStorage.username = '啊可接受的和就'
            // console.log(localStorage.data)
            // const btn = document.getElementById('btn')
            // btn.addEventListener('click', () => {
            //     let username = document.getElementById('username').value,
            //         age = document.getElementById('age').value
            //     let data = localStorage.getItem('data')
            //     if (data == null) {
            //         data = [
            //             {
            //                 username: username,
            //                 age: age,
            //             },
            //         ]
            //     } else {
            //         data = JSON.parse(data)
            //         data.push({
            //             username: username,
            //             age: age,
            //         })
            //     }
            //     localStorage.setItem('data', JSON.stringify(data))
            // })
            // del.addEventListener('click', () => {
            //     let data = localStorage.getItem('data')
            //     data = JSON.parse(data)
            //     data.splice(1, 1, {
            //         username: '肖自立',
            //         age: 18,
            //     })
            //     localStorage.setItem('data', JSON.stringify(data))
            // })
            // update.addEventListener('click', () => {
            //     let data = localStorage.getItem('data')
            //     data = JSON.parse(data)
            //     data[0].age = 99
            //     localStorage.setItem('data', JSON.stringify(data))
            // })
        }

        // localStorage.setItem('username', '张三')
        // localStorage.setItem('age', 18)
        // let arr = {
        //     username: '李四',
        //     age: 17,
        // }
        // localStorage.setItem('dataArr', JSON.stringify(arr))
        // console.log(JSON.parse(localStorage.getItem('dataArr')))
    </script>
</html>
